import {showStudentById,showStudent} from '../service'
export default {
    namespaced:true,
    state:{
        student:{},
        dialogVisible:false,
        students:[],
        pagination:{},
        type:"",
        value:""
    },
    mutations:{
        setDialogVisible(state,dialogVisible){
            state.dialogVisible = dialogVisible;
        },
        setStudent(state,student){
            state.student = student;
        },
        setStudents(state,students){
            state.students = students;
        },
        setPagination(state,pagination){
            state.pagination = pagination;
        },
        setType(state,type){
            state.type = type;
        },
        setValue(state,value){
            state.value = value;
        }
    },
    actions:{
        async setStudent(context,studentId){
            console.log("context",context);
            let response = await showStudentById(studentId);

            context.commit("setStudent",response.data);
        },
        async show(context,params){
            if(params && params.type){
                context.commit("setType",params.type);
                context.commit("setValue",params.value);
            }else{
                if(params){
                    params.type = context.state.type;
                    params.value = context.state.value;
                }
                
            }
            let response = await showStudent(params);
            context.commit("setPagination",response.data);
            context.commit("setStudents",response.data.list)
        }
    }
}